package com.evaluationSystem.controller;

import com.evaluationSystem.config.R;
import com.evaluationSystem.mapper.SystemDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName DuplicateController
 * @Description TODO
 * @Author yinzhenxing
 * @Date 2022/12/29 11:53
 **/
@RestController
@RequestMapping("/sys")
public class SystemController {
    @Autowired
    private SystemDao systemDao;

    @GetMapping("/duplicate/check")
    public R duplicateCheck(@RequestParam("tableName") String tableName,
                            @RequestParam("fieldName") String fieldName,
                            @RequestParam("fieldVal") String fieldVal,
                            Long dataId) {
        int count = systemDao.selectDuplicateCheck(tableName, fieldName, fieldVal, dataId);
        if (count > 0) {
            return R.failed("已检测到重复数据！");
        } else {
            return R.success();
        }
    }
}
